<?php
class HomeController extends AppController {
	var $uses = array('Review', 'User', 'School', 'SchoolRank');
	function index() {
		// Dem so luong danh gia
		$countReview = $this->Review->find('count');
		$countSchool = $this->School->find('count');
		$countUser = $this->User->find('count');
		
		$this->set(compact('countReview', 'countSchool', 'countUser'));
		
		// Lay danh sach truong tieu diem
		$tieuDiemSchools = $this->SchoolRank->find('all', array(
			'order' => 'tieu_diem_rank ASC',
			'limit' => 2
		));

		foreach ($tieuDiemSchools as $key => $school) {
			$schoolId = $school['School']['id'];
			$review = $this->Review->find('first', array(
				'conditions' => array('Review.school_id' => $schoolId)
			));
			$this->log($review, 'xxx');
			$tieuDiemSchools[$key]['Review'] = $review;
		}
		
		$bestForMoneySchools = $this->SchoolRank->find('all', array(
			'order' => 'best_value_for_money_rank ASC',
			'limit' => 2
		));

		foreach ($bestForMoneySchools as $key => $school) {
			$schoolId = $school['School']['id'];
			$review = $this->Review->find('first', array(
				'conditions' => array('Review.school_id' => $schoolId)
			));
			
			$bestForMoneySchools[$key]['Review'] = $review;
		}
		
		$this->set(compact('tieuDiemSchools', 'bestForMoneySchools'));
	}
	
	function about_us() {
		
	}
}